﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid;

namespace hpm
{
    public partial class frmKhoa : DevExpress.XtraEditors.XtraForm
    {

        clsKhoa obj_khoa = new clsKhoa();

        public frmKhoa()
        {
            InitializeComponent();
        }

        BindingList<clsKhoa> listKhoa = new BindingList<clsKhoa>();
        DataTable dtbKhoa = new DataTable();
        List<clsKhoa> lstKhoa = new List<clsKhoa>();
        
        private void frmKhoa_Load(object sender, EventArgs e)
        {
            InitList_Khoa();
        }

        void InitList_Khoa()
        {
            listKhoa.Add(new clsKhoa("KCC", "Khoa cấp cứu"));
            listKhoa.Add(new clsKhoa("KLBS", "Khoa Lưu bệnh sản"));
            grdKhoa.DataSource = listKhoa;
            grdKhoa.DataSource = this.obj_khoa.GetAll_Khoa();

            /*
            dtbKhoa = this.obj_khoa.GetAll_Khoa();
            lstKhoa = (from DataRow row in dtbKhoa.Rows
             select new clsKhoa
             {
                 MaKhoa = row["MaKhoa"].ToString(),
                 TenKhoa = row["TenKhoa"].ToString()

             }).ToList();
             */
             //grdKhoa.DataSource = lstKhoa;
       }

        private void brbtnClose_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.Close();
        }

        private void grdKhoa_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete && e.Modifiers == Keys.Control)
            {
                if (MessageBox.Show("Delete row?", "Confirmation", MessageBoxButtons.YesNo) != DialogResult.Yes)
                    return;

                grv_dmkhoa.DeleteSelectedRows();
                //grv_dmkhoa.DeleteRow(grv_dmkhoa.FocusedRowHandle);
            }
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            lstKhoa.Add(new clsKhoa("", ""));
            grdKhoa.DataSource = lstKhoa;
            grv_dmkhoa.RefreshData();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            //obj_khoa.dtbKhoa = obj_khoa.ConvertToDataTable(lstKhoa);
            obj_khoa.dtbKhoa = (DataTable) grdKhoa.DataSource;
            obj_khoa.CapNhatKhoa();
        }
    }
}